<?php
/**
 ** added by lss@2017/07/14
 ** 初始化 pk10_referral_probability 表 
**/

die('already done');
set_time_limit(0);
date_default_timezone_set("PRC");
include('./db_config.php');
$file_url = 'algo_data.txt';
$algo_data = file_get_contents($file_url);

//1.连接数据库->pdo方式
$db_pdo_link = pdo_write_read_link();

if(!empty($algo_data))
{
	$algo_data = unserialize($algo_data);
}else
{
	$sql = "select `algo_id` from  pk10_referral_algo";
	$algo_result = $db_pdo_link->query($sql);
	$algo_data = $algo_result->fetchAll(PDO::FETCH_ASSOC);
	if(count($algo_data)>=0)
	{
		file_put_contents($file_url,serialize($algo_data));
	}
}

if(!is_array($algo_data) || empty($algo_data))
{
	exit("获取公式失败");	
}

//3.定义计划种类
$guess_type_array = array('gjw','yjw','jjw','sjw','wjw','ljw','qjw','bjw','njw','tjw','q2zx','q3zx','gyhz','gyhzdx','gyhzds');

//4.定义统计概率的数据期数

$pro_array = array(
				'10' => '1',  //10期推荐计划统计概率
				'20' => '2',  //20期推荐计划统计概率
				'30' => '3',  //30期推荐计划统计概率
				'50' => '5'   //50期推荐计划统计概率
			);

$time = date('Y-m-d h:i:s');

foreach($algo_data as $algo_single)
{
	foreach($guess_type_array as $guess_type_single)
	{
		$insert_sql = "insert into `pk10_referral_probability`(guess_type_plan,guess_type,data_period,pro_result,addtime,updatetime) values('{$algo_single['algo_id']}','{$guess_type_single}','1','0','{$time}','{$time}'),('{$algo_single['algo_id']}','{$guess_type_single}','2','0','{$time}','{$time}'),('{$algo_single['algo_id']}','{$guess_type_single}','3','0','{$time}','{$time}'),('{$algo_single['algo_id']}','{$guess_type_single}','5','0','{$time}','{$time}')";
		
		echo $insert_sql;
		echo '\n';
		$proba_insert_result = $db_pdo_link->exec($insert_sql);
	}
}
